package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Identifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class IdentifierDaoImpl implements IdentifierDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addIdentifier(Identifier identifier) {
        String sql="insert into Identifier values(?,?,?,?,?,?,?,0,now())";
        return jdbcTemplate.update(sql,
                identifier.getIdentID(),
                identifier.getIdentCount(),
                identifier.getIdentPassword(),
                identifier.getIdentName(),
                identifier.getIdentSex(),
                identifier.getIdentBirth(),
                identifier.getIdentPhone());
    }

    public int deleteIdentifierByID(String identID) {
        String sql="update identifier set LogicalAddDel=0,LastModification=now() where IdentID=?";
        return jdbcTemplate.update(sql,identID);
    }


    public int updateIdentifier(Identifier identifier) {
        String sql="update identifier set IdentID=?,IdentCount=?,IdentPassword=?," +
                "IdentName=?,IdentSex=?,IdentBirth=?,IdentPhone=?,LastModification=now() where IdentID=?";
        return jdbcTemplate.update(sql,
                identifier.getIdentID(),
                identifier.getIdentCount(),
                identifier.getIdentPassword(),
                identifier.getIdentName(),
                identifier.getIdentSex(),
                identifier.getIdentBirth(),
                identifier.getIdentPhone(),
                identifier.getIdentID());
    }


    public List<Map<String,Object>> selectIdentifierByID(String identID) {
        String sql = "select * from identifier where IdentID = ?";
        return jdbcTemplate.queryForList(sql,identID);
    }



    public List<Map<String,Object>> getAllIdentifier() {
        String sql="select * from identifier";
        return jdbcTemplate.queryForList(sql);
    }
}

